package com.zlzkj.app.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

//import com.zlzkj.core.mybatis.SqlRunner;
import com.zlzkj.core.sql.Row;
//import com.zlzkj.core.sql.SQLBuilder;
//import com.zlzkj.core.util.Fn;
import com.zlzkj.app.mapper.MonitorMapper;
import com.zlzkj.app.model.Monitor;
import com.zlzkj.app.util.IDGenerator;
//import com.zlzkj.app.util.Md5Util;
import com.zlzkj.app.util.Page;

@Service
@Transactional
public class MonitorService {

	@Value("${PAGE_SIZE}")
	private int PAGE_SIZE;

	@Autowired
	private MonitorMapper mapper;
	
//	@Autowired
//	private SqlRunner sqlRunner;

	//新增
	public Integer save(Monitor entity) {
		entity.setId(IDGenerator.generator());
		entity.setOrdinary(0);
		entity.setSerious(0);
		return mapper.insert(entity);
	}

    //根据id删除
    public Integer delete(String id){
        return mapper.deleteByPrimaryKey(id);
    }

    public Integer deletebyIds(String[]id){
        Map parmMap = new HashMap();
        parmMap.put("ids",id);
        return mapper.deleteByMap(parmMap);
    }

    //根据主键更新
    public Integer update(Monitor entity){
        return mapper.updateByPrimaryKey(entity);
    }

    //根据主键查找
	public Monitor findById(String id){
	    return mapper.selectByPrimaryKey(id);
	}
	
	public List<Row> findByMap(Map<String,Object> map){
	    return mapper.selectByMap(map);
	}

	public Page findByMap(Map<String,Object> parmMap,Integer nowPage) {
		if(nowPage == null) nowPage = 1;
		parmMap.put("start",(nowPage-1)*PAGE_SIZE);
		parmMap.put("end",PAGE_SIZE);
		return new Page(findByMap(parmMap),mapper.countByMap(parmMap),nowPage,PAGE_SIZE);
	}

//	public List<Row> findByMap(Map<String,Object> map){
//		return mapper.selectByMap(map);
//	}

//	public Page findByMap(Map<String,Object> parmMap,Integer nowPage){
//		if(nowPage == null) nowPage = 1;
//		parmMap.put("start",(nowPage-1)*PAGE_SIZE);
//		parmMap.put("end",PAGE_SIZE);
//		return new Page(findByMap(parmMap),mapper.countByMap(parmMap),nowPage,PAGE_SIZE);
//	}

}


